import request from "@/utils/request";
import { rootsUrl } from "../utils";
import { getToken } from "@/utils/auth";
import Qs from "qs";

//------------ 典藏 开始 ------------
/**
 * 获取文物是否已点赞。
 * @param {Number} id 文物主键
 */
export const hasThumbsUp = id => {
  let token = getToken();
  return request({
    url: `${rootsUrl[0]}/museum/thumbsup/hasThumbsup.shtml`,
    method: "get",
    params: {
      id,
      token,
      type: 1
    }
  });
};

/**
 * 给某个特定的文物点赞
 * @param {Number} id 文物主键
 */
export const thumbsUp = id => {
  let token = getToken();
  return request({
    url: `${rootsUrl[0]}/museum/thumbsup.shtml`,
    method: "get",
    params: {
      id,
      token,
      type: 1
    }
  });
};
//------------ 典藏 结束 ------------

/**
 * 留言薄
 * @param {*} obj
 */
export const saveMessageFromUser = obj => {
  let token = getToken();
  let data = {
    messageTitle: obj.title,
    name: obj.name,
    mobile: obj.mobile,
    messageContent: obj.content,
    email: obj.email
  };
  return request({
    url: `${rootsUrl[0]}/museum/messageboard/save.shtml`,
    method: "post",
    headers: {
      "Content-type": "application/x-www-form-urlencoded"
    },
    data: Qs.stringify(data)
  });
};

/**
 * 加入志愿者
 * @param {*} obj
 */
export const applyVolunteer = obj => {
  return request({
    url: `${rootsUrl[4]}/WebService/WXIOHandler.ashx?t=vbaoming`,
    method: "post",
    headers: {
      "Content-type": "application/x-www-form-urlencoded"
    },
    data: Qs.stringify(obj)
  });
};
